<?php
// +----------------------------------------------------------------------
// | When work is a pleasure, life is a joy!
// +----------------------------------------------------------------------
// | User: ShouKun Liu  |  Email:24147287@qq.com  | Time:2017/1/23 22:06
// +----------------------------------------------------------------------
// | TITLE: 更新记录
// +----------------------------------------------------------------------

namespace Qwadmin\Controller;


use Common\Model\OrderUpdateModel;
use Think\Page;

class OrderUpdateController extends ComController
{


    public function lists()
    {

        $where = I('');
        if (!empty($where['mobile'])) $wheres['mobile'] = array('like', "%$where[mobile]%");
        if (!empty($where['taobao_pay'])) $wheres['taobao_pay'] = array('like', "%$where[taobao_pay]%");
        if (!empty($where['origin'])) $wheres['origin'] = array('like', "%$where[origin]%");
        if (!empty($wheres)) {
            $wheres['_logic'] = 'and';
            $map['_complex'] = $wheres;
        }
        if (!empty($where['status'])) $map['status'] = $where['status'];

        if (empty($map['_complex'])) {
            $time = I('time');
            $start = (empty($time)) ? date('Y-m-d 00:00:00') : $time;
            $end = (empty($time)) ? date('Y-m-d 00:00:00') : $time;
            $start = strtotime(date('Y-m-d 00:00:00', strtotime($start)));
            $end = strtotime(date('Y-m-d 23:59:59', strtotime($end)));
            $map['create_time'] = array(array('gt', $start), array('lt', $end), 'and');
        }

        $pageSize = I('pageSize', '20');
        $orderUpdateController = new OrderUpdateModel();
        $count = $orderUpdateController->where($map)->count();

        $Page = new Page($count, $pageSize);
        $orderList =
            $orderUpdateController
                ->where($map)
                ->order('status asc, id desc')
                ->limit($Page->firstRow, $Page->listRows)
                ->select();
        $this->assign('page', $Page->show());
        $this->assign('list', $orderList);
        $this->display();
    }

    public function edit()
    {

        $id = I('id');
        if (empty($id)) $this->error('错误');
        $orderUpdateModel = new OrderUpdateModel();
        $model = $orderUpdateModel->where(array('id' => $id))->find();
        if ($model == false) $this->error('错误');


        if (IS_POST) {
            $data = I('');
            $data['update_user'] = $this->USER['user'];
            $result=$orderUpdateModel->editOrderUpdate($data);
            if ($result==false){
                $this->error('失败');
            }else {
                $this->success('成功');
            }

        } else {

            //获取状态
            $this->assign('statusList', OrderUpdateModel::$statusList);
            $this->assign('orderInfo',$model);
            $this->display();
        }
    }


}